package Math类;

public class PentagonalNumber {

	public static void main(String[] args) {
		/*int i = 0;
		while(i<100){
			if(i % 10 == 0)
				System.out.println();
			System.out.print(getPentagonalNumber(i) +" ");
			i++;
		}*/
		int i = sumDe(4321);
		System.out.println(i);
	}
	
	/**
	 * 返回五角数
	 * @param n
	 * @return
	 */
	public static int getPentagonalNumber(int n){
		
		return n * (3 * n - 1) / 2;
	}
	
	/**
	 * 递归	
	 * 一个整数各位数之和
	 * @param n
	 * @return
	 */
	public static int sumDigits(long n){
		if (n < 0) {
			n = -n;
		}
		if (n % 10 == n) {
			return (int) n;
		} else {
			return (int) (n % 10 + sumDigits(n / 10));
		}
	}
	
	/**
	 * 整数的各位数之和
	 * @param n
	 * @return
	 */
	public static int sumDe(long n){
		if(n % 10 == n){
			return (int) n;                                                                                                 
		}
		return (int) (n % 10 +sumDe(n/10));
	}
}
